package com.example.myapplication.apter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Cat.ParkingDtailsActivity;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.Re_Catcomit;
import com.example.myapplication.ShuJu.Re_News;

import java.util.List;

public class CatcomitAdapter extends RecyclerView.Adapter<CatcomitAdapter.MyHolder>{
    private Context context;
    private List<Re_Catcomit.RowsDTO> list;

    public CatcomitAdapter(Context context, List<Re_Catcomit.RowsDTO> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public CatcomitAdapter.MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_cat,null);
        return new CatcomitAdapter.MyHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull CatcomitAdapter.MyHolder holder, int position) {
            Glide.with(context).load(list.get(position).getImgUrl()).into(holder.car_img);
            holder.cat_name.setText("停车场名: "+list.get(position).getParkName());
            holder.cat_num.setText("空位数量: "+String.valueOf(list.get(position).getVacancy()));
            holder.cat_dizi.setText("停车场地址: "+String.valueOf(list.get(position).getAddress()));
            holder.car_price.setText("收费价格: "+String.valueOf(list.get(position).getRates())+"元");
            holder.rootView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, ParkingDtailsActivity.class);
                    intent.putExtra("listID",String.valueOf(list.get(position).getId()));
                    context.startActivity(intent);
                }
            });
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {
        ImageView car_img;
        TextView cat_name;
        TextView cat_num;
        TextView cat_dizi;
        RelativeLayout rootView;
        TextView car_price;
        public MyHolder(@NonNull View itemView) {
            super(itemView);
            car_img = itemView.findViewById(R.id.car_img);
            cat_dizi = itemView.findViewById(R.id.cat_dizi);
            cat_name = itemView.findViewById(R.id.cat_name);
            rootView = itemView.findViewById(R.id.rootView);
            cat_num = itemView.findViewById(R.id.cat_num);
            car_price = itemView.findViewById(R.id.car_price);
        }
    }
}


